package com.koron.sinoprobe.web.engineering.workflow;

import com.koron.bean.base.Response;
import com.koron.bean.workflow.SubmitterParam;
import com.koron.bean.workflow.WorkflowUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * @author jzp
 * @since 2022/1/20
 */
@Slf4j
@RequestMapping("sp/common/workflow")
@RestController
public class CommonWorkflowController {
    @Autowired
    private StaffHelper staffHelper;

    /**
     * 选人组件过滤规则
     * <p>
     * 插件是啥就是啥
     */
    @PostMapping("default/handler")
    public Response<List<WorkflowUser>> defaultHandler(@RequestBody SubmitterParam submitterParam) {
        List<WorkflowUser> results = staffHelper.getPostUserQuery(submitterParam.getUsers(), null);
        return Response.ok(results);
    }

    /**
     * 选人组件过滤规则
     * <p>
     * 默认添加编制人所在部门
     */
    @PostMapping("authorizer/handler")
    public Response<List<WorkflowUser>> authorizerHandler(@RequestBody SubmitterParam submitterParam, String authorizer) {
        staffHelper.fillAuthorizerOrg(submitterParam, authorizer);
        List<WorkflowUser> results = staffHelper.getPostUserQuery(submitterParam.getUsers(), null);
        return Response.ok(results);
    }

    /**
     * 选人组件过滤规则
     * <p>
     * 默认并集
     */
    @PostMapping("default/submitter")
    public Response<List<WorkflowUser>> defaultSubmitter(@RequestBody SubmitterParam submitterParam) {
        List<WorkflowUser> results = staffHelper.getPostUserQuery(submitterParam.getUsers(), null);
        return Response.ok(results);
    }

    /**
     * 选人组件过滤规则
     * <p>
     * 交集
     */
    @PostMapping("mixed/submitter")
    public Response<List<WorkflowUser>> mixedSubmitter(@RequestBody SubmitterParam submitterParam) {
        return Response.ok(staffHelper.mixed(submitterParam.getUsers()));
    }

}
